package com.luli.controllor;

import ch.ethz.ssh2.Connection;
import com.luli.Utils.RemoteCommandUtil;
import com.luli.entity.response.ResponseMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.filechooser.FileSystemView;
import java.awt.*;
import java.io.IOException;

import static com.luli.Utils.RemoteCommandUtil.login;
import static com.luli.Utils.ResponseMsgUtil.getFailMsg;
import static com.luli.Utils.ResponseMsgUtil.getSuccessMsg;

/**
 * 陆离
 * 2022/11/15 9:35:12
 */
@RestController
@Slf4j
@RequestMapping("/file")
@CrossOrigin
public class FileController {


    /**
     * 127.0.0.1:8081/LuLi/file/downFile
     * @param fileName
     * @return
     * @throws IOException
     */
    @GetMapping("/downFile")
    public void downFile(String fileName) throws IOException {
       try {
           // 创建服务对象
           RemoteCommandUtil commandUtil = new RemoteCommandUtil();
           // 登录到Linux服务
           Connection root = login("192.168.175.135", "root", "lzp+19991128");
           // 服务器文件路径
           String fwPath = "/file/jiangTianLanTai/";
           // windows本地存放目录，不需要加上具体文件
           FileSystemView fsv = FileSystemView.getFileSystemView();
//           String deskTopPath = fsv.getHomeDirectory().getAbsolutePath();
           String deskTopPath = "C:\\Users\\lenovo\\Desktop\\江天兰台\\下载文件测试\\";
           // 下载文件
           commandUtil.downloadFile(root,"归档文件目录封面.docx",fwPath,deskTopPath,null);
       }catch (Exception e){
           log.error("Error:"+e.getMessage());
       }
    }

    public static void main(String[] args) {
        FileSystemView fsv = FileSystemView.getFileSystemView();
        String deskTopPath = fsv.getHomeDirectory().getAbsolutePath();
        System.out.println(deskTopPath);
    }
}
